import api from '../../api';
import { message } from 'antd';

export default {
  namespace: 'splitPositionQueryM',

  state: {
    tableData: { columns: [], dataSource: [] },
  },

  effects: {
    //查看产品下拉列表
    *queryProductIdList({ payload, callback }, { call, put }) {
      const response = yield call(api.initialSplit.queryProductList, payload);
      if (response) {
        if (response.code == 0) {
          callback('success', response.data.dataSource || []);
        } else {
          callback('fail');
          message.error(response.msg || '查询产品下拉列表失败!');
        }
      } else {
        callback('fail');
        message.error('查询产品下拉列表失败!');
      }
    },
    //查询系列产品持仓表格
    *queryTableList({ payload, callback }, { call, put }) {
      const response = yield call(api.splitPositionQuery.queryHoldList, payload);
      if (response) {
        if (response.code == 0) {
          callback('success', response.data);
        } else {
          callback('fail');
          message.error(response.msg || '查询系列产品持仓失败!');
        }
      } else {
        callback('fail');
        message.error('查询系列产品持仓失败!');
      }
    },
    //查询真实持仓表格
    *queryTableListReal({ payload, callback }, { call, put }) {
      const response = yield call(api.splitPositionQuery.queryHoldListReal, payload);
      if (response) {
        if (response.code == 0) {
          callback('success', response.data);
        } else {
          callback('fail');
          message.error(response.msg || '查询真实持仓失败!');
        }
      } else {
        callback('fail');
        message.error('查询真实持仓失败!');
      }
    },
    //查询资产的真实持仓
    *queryHoldListRealByAid({ payload, callback }, { call, put }) {
      const response = yield call(api.splitPositionQuery.queryHoldListRealByAid, payload);
      if (response) {
        if (response.code == 0) {
          callback('success', response.data);
        } else {
          callback('fail');
          message.error(response.msg || '查询资产的真实持仓失败!');
        }
      } else {
        callback('fail');
        message.error('查询资产的真实持仓失败!');
      }
    },
  },

  reducers: {
    save(state, { payload }) {
      return {
        ...state,
        ...payload,
      };
    },
  },
};
